package game;

import java.util.LinkedList;
import java.util.List;

public class GunshotManager
{
	public GunshotManager(CollisionChecker collisionChecker)
	{
		this.collisionChecker = collisionChecker;
	}
	
	public void update(long deltaTime)
	{
		for (int i = 0; i < gunshots.size(); i++)
		{
			if (gunshots.get(i).isDestroyed())
			{
				collisionChecker.removeGunshot(gunshots.get(i));
				gunshots.remove(i);
				continue;
			}
			
			gunshots.get(i).update(deltaTime);
		}
	}
	
	public void redraw(int cameraX, int cameraY)
	{
		for (int i = 0; i < gunshots.size(); i++)
		{
			gunshots.get(i).redraw(cameraX, cameraY);
		}
	}
	
	public void addGunshot(Gunshot gunshot)
	{
		this.collisionChecker.addCollidableObject(gunshot);
		this.gunshots.add(gunshot);
	}
	
	public void removeAll()
	{
		for (int i = 0; i < gunshots.size(); i++)
		{
			collisionChecker.removeGunshot(gunshots.get(i));
		}

		this.gunshots.clear();
	}
	
	private CollisionChecker collisionChecker;
	private List<Gunshot> gunshots = new LinkedList<Gunshot>();
}
